home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / arexx / cg / cghaiku.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-07  |  12KB  |  374 lines

  1. /* A haiku generator CMD: Haiku                           */
  2. /* from "Using ARexx on the Amiga" by Sullivan and Zamara */
  3. /* CGized By Bob C.                                       */
  4. /* Adapted By Arnie                                       */
  5. /* Encrufted by Robert                                    */
  6. /* Tue Dec  1 22:45:53 1992                               */
  7.  
  8. call addlib "CG_AREXX", 0
  9.  
  10. call InitVocab()
  11. call random(,,time('s'))
  12.  
  13. page = GET_PAGE()
  14.    call SET_PAGE(NEXT)
  15.    if page_is_blank() then do
  16.        call SET_PAGE(TYPE,Framestore)
  17.        call GenHaiku()
  18.        end
  19.    else do
  20.       call KILLPAGE(page)
  21.       call SET_PAGE(TYPE,Framestore)
  22.       if page_is_blank() then
  23.          call GenHaiku()
  24.       end
  25.    page = GET_PAGE()
  26. exit
  27.  
  28.  
  29. /* GenHaiku
  30.  
  31.    Generate and return a single Haiku poem
  32. */
  33. GenHaiku:
  34.    /* Select a template, parse it into 3 lines, and clear output buffer. */
  35.    t = random(1,num_templates)
  36.    parse var tem.t line.1 '+' line.2 '+' line.3
  37.    out. = ''
  38.  
  39.    /* Process template lines one at a time. */
  40.    do i=1 to 3
  41.  
  42.       /* Keep going till template line exhausted. */
  43.       do while length(line.i) > 0
  44.          parse var line.i cmd 3 qual 4 line.i
  45.  
  46.          c = left(cmd, 1)
  47.          ucmd = upper(cmd)
  48.  
  49.          if v.ucmd ~= "" then do
  50.             w = word(v.ucmd, random(1, words(v.ucmd)))
  51.  
  52.             if datatype(c, 'u') then
  53.                w = upper(left(w, 1))substr(w, 2)
  54.  
  55.             upper c
  56.  
  57.             if c='V' & qual='@' then
  58.                w = add_ing(w)
  59.             else if c='N' & qual='s' then
  60.                w = pluralize(w)
  61.             else
  62.                line.i = qual || line.i
  63.  
  64.             end
  65.          else if c='/' then do
  66.             parse value cmd || qual || line.i with '/' list '/' line.i
  67.             w = word(list, random(1, words(list)))
  68.             end
  69.          else
  70.             parse value cmd || qual || line.i with w 2 line.i
  71.  
  72.          out.i = out.i || w
  73.          end
  74.       end
  75.       out.1=translate(out.1,' ','_')
  76.       out.2=translate(out.2,' ','_')
  77.       out.3=translate(out.3,' ','_')
  78.       call MAKELINE(out.1)
  79.       call PICKLINE()
  80.       call SET_LINE(JUST,Center)
  81.       call MAKELINE(out.2)
  82.       call PICKLINE()
  83.       call SET_LINE(JUST,Center)
  84.       call MAKELINE(out.3)
  85.       call PICKLINE()
  86.       call SET_LINE(JUST,Center)
  87.       call PICKPAGE()
  88.    return
  89.  
  90.  
  91. /* Add_Ing
  92.  
  93.    Add the `ing' suffix to the given verb. The trick here is to double
  94.    the final consonant of the verb in many but not all instances. The
  95.    exception list and the code that employs take care of this. When new
  96.    verbs are added to the vocabulary lists, consider whether the `ing'
  97.    form is exceptional.
  98. */
  99. add_ing: procedure
  100.  
  101.    exc. = 0
  102.    exc.withdraw = 1
  103.    exc.wander  = 1
  104.    exc.snarf   =1
  105.    exc.wallow  = 1
  106.    exc.flicker = 1
  107.    exc.shiver  = 1
  108.    exc.wonder  = 1
  109.    exc.edit  = 1
  110.    exc.render  = 1
  111.    exc.pay  = 1
  112.    exc.eat  = 1
  113.    exc.walk = 1
  114.    exc.shoot = 1
  115.    exc.fling = 1
  116.    exc.speak = 1
  117.    exc.flow = 1
  118.    exc.crawl = 1
  119.    exc.creep = 1
  120.    exc.reek = 1
  121.    exc.sink = 1
  122.    exc.croak = 1
  123.    exc.burn = 1
  124.    exc.stink = 1
  125.    exc.steal = 1
  126.    exc.peel = 1
  127.    exc.kill = 1
  128.    exc.toast = 1
  129.    exc.rent = 1
  130.    exc.drink = 1
  131.    exc.Smooth = 1
  132.    exc.Load = 1
  133.    exc.Stretch = 1
  134.    exc.Clear = 1
  135.    exc.Patch = 1
  136.    exc.Morph = 1
  137.    exc.destroy = 1
  138.    exc.accept = 1
  139.    exc.reboot = 1
  140.    exc.despair = 1
  141.    exc.descend = 1
  142.    exc.command = 1
  143.    exc.broadcast = 1
  144.    exc.shiver = 1
  145.    exc.Jitter = 1
  146.    exc.Mirror = 1
  147.    exc.Bevel = 1
  148.    exc.Align = 1
  149.    exc.encruft = 1
  150.    exc.command = 1
  151.    exc.splatter = 1
  152.    exv  = upper(arg(1))
  153.  
  154.    parse value arg(1) with 100 -3 l3 +1 l2 +1 l1
  155.  
  156.    if index("mbgprndlt",l1)>0 & index("aeiou",l2)>0 & index("aeiou",l3)=0 then do
  157.       if ~exc.exv then
  158.          w = arg(1) || l1
  159.       else
  160.          w = arg(1)
  161.       end
  162.    else if l1='e' then
  163.       w = left(arg(1), length(arg(1)) - 1)
  164.    else
  165.       w = arg(1)
  166.  
  167.    return w || 'ing'
  168.  
  169.  
  170. /* Pluralize
  171.  
  172.    Pluralize the given word, taking account of certain exceptions. If you
  173.    add nouns to the vocabulary lists, consider whether the pluralization
  174.    is exceptional.
  175. */
  176. pluralize: procedure expose v.
  177.  
  178.    exc. = 0
  179.    exc.ice  = 1
  180.    exc.beach   = 1
  181.    exc.spooge  = 1
  182.    exc.kluge  = 1
  183.    exc.mouse   = 1
  184.    exc.moose   = 1
  185.    exc.bass    = 1
  186.    exc.box     = 1
  187.    exc.peach   = 1
  188.    exc.glance  = 1
  189.    exc.bus     = 1
  190.    exc.juice   = 1
  191.    exc.paintbox = 2
  192.    exc.Image   = 2
  193.    exc.Sequence = 2
  194.    exc.lotus   = 2
  195.    exc.gecko   = 10
  196.    exc.cry     = 11
  197.    exc.dei     = 12
  198.  
  199.    w  = arg(1)
  200.    uw = upper(w)
  201.  
  202.    /* Nouns with an exception code of 1 or 2 have 1 or 2 syllables
  203.       respectively in the singular, but an extra syllable in the plural.
  204.       Since the syllables must remain constant, we replace such a noun
  205.       with another from its list, until we find one that is not lengthened
  206.       by pluralization.
  207.    */
  208.    do while exc.uw > 0 & exc.uw < 10
  209.       list = value('v.n'exc.uw)
  210.       w    = word(list, random(1, words(list)))
  211.       uw   = upper(w)
  212.       end
  213.  
  214.    /* Match capitalization of argument word with (possibly) new word. */
  215.    if datatype(left(arg(1),1),'u') then
  216.       w = upper(left(w,1))substr(w,2)
  217.  
  218.    /* Pluralize */
  219.    select
  220.       when exc.uw =  0 then w = w || 's'
  221.       when exc.uw = 10 then w = w || 'es'
  222.       when exc.uw = 11 then w = left(w,2) || 'es'
  223.       otherwise
  224.          call inform("Invalid pluralize exception" exc.uw)
  225.          exit
  226.       end
  227.  
  228.    return w
  229.  
  230.  
  231. InitVocab:
  232.  
  233. v. = ""
  234.  
  235. /* Adjectives, one syllable */
  236. av.a1 = "quick wild small hot white wet blue pink old light dark"
  237. v.a1 = v.a1 "sad deep lost free drunk slow dumb hard soft damp dry"
  238. v.a1 = v.a1 "tight loose gross cold clean proud dead plaid munged nuked"
  239. v.a1 = v.a1 "strong weak young dull ill mean flat sharp kluged tweaked"
  240. v.a1 = v.a1 "wudge freak"
  241.  
  242. /* Adjectives, two syllables */
  243. v.a2 = "evil putrid empty crooked runny fallen dismal crufty"
  244. v.a2 = v.a2 "potent rabid gnarly golden hairy wrinkled cuspy"
  245. v.a2 = v.a2 "robust rancid smiling toasted paisley dying measly"
  246. v.a2 = v.a2 "brain_dead stupid plastic bogus lo-res frothy 3D hi-res"
  247. v.a2 = v.a2 "opaque diffuse default wireframe print-res angry flattened"
  248.  
  249. /* Nouns, one syllables */
  250. v.n1 = "goat moose cat stream kluge fade mouse sprite bomb bass disc box"
  251. v.n1 = v.n1 "worm hack moon dog glance flame spooge cow pig shell cone Fudd"
  252. v.n1 = v.n1 "frob Spam curve spline clone duck sea hand fish neck growth ice"
  253. v.n1 = v.n1 "point sync deck cop food RAM wine beer car bus bike juice ball"
  254. v.n1 = v.n1 "box light scene key bone frame fog sky ground view stat Duff"
  255.  
  256. /* Nouns, two syllables */
  257. v.n2 = "shadow forest guitar keyboard missile toaster teapot pointer guru"
  258. v.n2 = v.n2 "ooblick chomper dissolve parrot budgie info volume red_head"
  259. v.n2 = v.n2 "CD valley switcher cookie framestore farmer hard_disk wetware"
  260. v.n2 = v.n2 "Toaster LightWave model object cheese_shop option splitter"
  261. v.n2 = v.n2 "CG starship airport sports_car pudding oatmeal layout weasel wirehead"
  262. v.n2 = v.n2 "image preview shadow bump_map color segment motion widget"
  263. v.n2 = v.n2 "lens_flare spot_light backdrop zenith nadir program hacker"
  264. v.n2 = v.n2 "Flyer Screamer Rapter"
  265.  
  266. /* Verbs, one syllable */
  267. v.v1 = "walk eat grab shoot fling frag stick speak flow live cut paste"
  268. v.v1 = v.v1 "rip crawl creep reek bite sink take croak burn stop stink flip"
  269. v.v1 = v.v1 "spit shine steal fade peel crave kill stab writhe split"
  270. v.v1 = v.v1 "dub toast tape cut rent burn shop chomp pay drink eat snore"
  271. v.v1 = v.v1 "make smooth load save clear lathe blast ride"
  272. v.v1 = v.v1 "clone skin morph grok mung phreak count nuke snarf"
  273.  
  274. /* Verbs, two syllables */
  275. v.v2 = "explode desire adlib destroy decline accept dissolve endure reboot"
  276. v.v2 = v.v2 "rebel retire despair encode wonder bubble flicker grumble"
  277. v.v2 = v.v2 "decode descend compile command render edit broadcast shiver wallow"
  278. v.v2 = v.v2 "jitter combine copy bevel rotate splatter command withdraw"
  279. v.v2 = v.v2 "align extrude mirror flatline encruft guru"
  280.  
  281. /* Verbs, one syllable, transitive */
  282. v.v3 = "eat grab shoot cut rip bite sink take burn stop flip steal peel crave"
  283. v.v3 = v.v3 "stab split scream toast chomp drink save blast ride clone mung"
  284. v.v3 = v.v3 "snarf nuke kill find own lose keep know see smell hear taste feel"
  285.  
  286. /* Verbs, one syllable, transitive, past tense */
  287. v.t1 = "ate killed shot cut bit sank burned stopped stole found lost smashed"
  288. v.t1 = v.t1 "chomped drank munged nuked snarfed took boned"
  289.  
  290. /* Prepositions, one syllable */
  291. v.p1 = "on of in near past at by in through from"
  292.  
  293. /* Prepositions, two syllables */
  294. v.p2 = "left_of upon under beside over west_of beyond above below around"
  295. v.p2 = v.p2 "inside outside next_to far_from behind"
  296.  
  297. /* Relative adverbs, one syllable */
  298. v.r1 = "where when while as"
  299.  
  300. /* Little words that can precede nouns, biased towards `the' */
  301. v.l1 = "the God's Hell's this my Bob's your his her the Ken's Ron's Moe's"
  302. v.l1 = v.l1 "Skell's Mark's Paul's Tim's James' Dawn's Penn's its our the Wil's"
  303. v.l1 = v.l1 "Kirk's Spock's Worf's Q's Croooow's Joel's Bart's  Dreux's"
  304. v.l1 = v.l1 "Death's Jud's Dan's Dick's some all Ren's Charles' Anne's Steve's"
  305. v.l1 = v.l1 "Grue's Chuck's Gregs's Chris's Todd's Simba's Nala's Brad's"
  306. v.l1 = v.l1 "Greg's Grue's Bob's Lloyd's"
  307.  
  308. /* Names, two syllables */
  309. v.h2 = "Robert NewTek Pink_Floyd Tami Smithers Billy Flanders Londo"
  310. v.h2 = v.h2 "David Yoko Arnie Satan Jesus Homer Kerri Barney"
  311. v.h2 = v.h2 "Ervin Batman Robin Mofo some_jerk James_Bond"
  312. v.h2 = v.h2 "Kiki Simone Lobo Ayn_Rand John_Cleese Elvis Allen"
  313. v.h2 = v.h2 "Peter Kenbe Junior Daniel Teller Kristy Kelly Stuart"
  314. v.h2 = v.h2 "Dana Picard Riker Data Geordi Crusher Milhouse Apu Laura Tammy"
  315. v.h2 = v.h2 "Cambot Gypsy Alex Bobbi Lisa Maggie Porter Stephen Mojo Stimpy"
  316. v.h2 = v.h2 "JoJo Jason"
  317.  
  318. /* Haiku templates
  319.  
  320.    The special tokens in the templates are:
  321.  
  322.    a1,n2 etc.     Part of speech, replaced randomly from corresponding list
  323.    A1,N2 etc.     Same, but with initial capital
  324.    +              Converted to linefeed
  325.    @              After verb, specifies conversion to `ing' (gerund) form
  326.    s              After noun, specifies conversion to plural form
  327.    /wordlist.../  Replaced by a word picked randomly from the list
  328.  
  329.    All other symbols in the templates are taken literally.
  330. */
  331. tem.  = ""
  332. tem.1 = "A1 n1, a2 n1.+L1 a1, a2 n2 v1s.+A1 n1, a1 n2."
  333. tem.2 = "P2 the a1 n1,+R1 the a2 n2 v1s,+I v1; the n1 v1s."
  334. tem.3 = "The a1 n1 v1@;+It is the a2 n2.+V2@, I v1."
  335. tem.4 = "The a2 n1 v1s+R1 a2 n2s v2.+Does the a1 n1 v1?"
  336. tem.5 = "Not a1, but a2,+H2 comes to the n2.+L1 a1 n2 v1s."
  337. tem.6 = "A1, a2, a2,+H2 v1s. H2 v2s,+V2@, v1@."
  338. tem.7 = "/Never Sometimes/ a1, but a1,+H2 knows /no my some all/ a1 n2s.+A2, /he she/ v2s."
  339. tem.8 = "/Not Quite/ a1, /and but or/ a2,+H2 comes to the n2.+L1 a1 n2 v1s."
  340. tem.9 = "A1 n1, a2 n1.+L1 a1, a2 n2 v1s.+A1 n1, a1 n2."
  341. tem.10 = "The a2 n1 v1s +R1 a2 n2s v2.+Does the a1 n1 v1?"
  342. tem.11 = "Not a1, but a2,+H2 comes to the n2.+L1 a1 n2 v1s."
  343. tem.12 = "A1, a2, a2,+H2 v1s. H2 v2s,+V2@, v1@."
  344. tem.13 = "Hey! Get back to work +You lazy, no good n2. +The world is v1@!"
  345. tem.14 = "If n2s could v1, +And v3 l1 n2 today, +The n1 would v3 you."
  346. tem.15 = "If n2s could v1, +And v3 l1 n2 today, +The n1 would v3 you."
  347. tem.16 = "As the n1 draws near, +H2 v3s our n1. You must +V3 the a1 n2."
  348. tem.17 = "Alone the a1 n1 v1s. +'Where is my n2?', you ask. +/Ack! Doh! Oops!/ H2 t1 it."
  349. tem.18 = "Attention all n1s! +When v1@ n2s v2, +It's time to v2."
  350.  
  351. do i=1 while tem.i ~= ""
  352.    end
  353.  
  354. num_templates = i - 1
  355.  
  356. return
  357.  
  358. syntax:
  359. error:
  360.         t=REQ_TELL('Rexx Script Error')
  361.         exit
  362.  
  363.  
  364. page_is_blank:
  365.   page_size=GET_PAGE(SIZE)
  366.   line_size=GET_LINE(SIZE)
  367.   if (page_size = 0 | page_size = 1) & line_size = 0 then
  368.      return 1
  369.   else
  370.      return 0
  371.  
  372.  
  373.  
  374.